﻿namespace SupportSystemUI.Controls.CustomPages.Crew
{
    using System.Collections.Generic;
    using System.Windows.Controls;
    using System.Windows.Media;
    using SupportSystemDB;
    using SupportSystemUI.Controls.Pages;

    /// <summary>
    /// Interaction logic for EventItem.xaml
    /// </summary>
    public partial class EventItem : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="EventItem"/> class.
        /// </summary>
        /// <param name="eventData">Data of the displayed event.</param>
        public EventItem(Event eventData)
        {
            this.InitializeComponent();

            this.imageIcon.SetImage(eventData.Logo);
            this.nameBlock.Text = eventData.Name;
            this.fromBlock.Text = eventData.StartDate.ToShortDateString();
            this.toBlock.Text = eventData.EndDate.ToShortDateString();

            this.MouseEnter += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
            };
            this.MouseLeave += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Colors.White);
            };
            this.MouseUp += (sender, args) =>
            {
                Global.Instance.PagesScreen.Push(
                    () => eventData,
                    (data) => new PageData(new EventPage(data as Event), eventData.Name + " Information"));
            };
        }

        /// <summary>
        /// Returns the control filled with the provided data.
        /// </summary>
        /// <param name="data">Data object to use.</param>
        /// <returns>A PageData object.</returns>
        public static PageData View(object data)
        {
            StackPanel panel = new StackPanel();
            foreach (Event item in data as List<Event>)
            {
                panel.Children.Add(new EventItem(item));
            }

            return new PageData(panel, "Year's Events");
        }
    }
}
